import http from '@/http/interceptor'
import ciphertext from '@/utils/ciphertext-util'

let BASE_USER_CONTENT = '/sys/user'
/** 获取用户 **/
export function getUserInfo() {
	return http({
		url: BASE_USER_CONTENT + '/info',
		method: 'get',
		params: http.queryData()
	})
}

/** 修改密码 **/
export function updatePassword(dataForm) {
	return http({
		url: BASE_USER_CONTENT + '/password',
		method: 'put',
		data: http.jsonData({
			'password': ciphertext.encode(dataForm.oldPassword),
			'newPassword': ciphertext.encode(dataForm.newPassword)
		})
	})
}

/** 修改用户信息 **/
export function updateUser(data = {}) {
	return http({
		url: BASE_USER_CONTENT + '/' + 'update',
		method: 'put',
		data: http.jsonData({
			id: data.id || 0,
			userName: data.userName,
			password: ciphertext.encode(data.password),
			status: data.status,
			expired: data.expired,
			roleIds: data.roleIds || []
		}),
		loading: false
	})
}
